<switch name="type">
    <case value="1">
        <input id="real_name" value="{BEESCRM:$info.real_name}"/>
    </case>
    <case value="2">
        <input id="number" value="{BEESCRM:$info.number}"/>
    </case>
    <case value="3">
        <input id="mobile" value="{BEESCRM:$info.mobile}"/>
    </case>
    <case value="4">
        <select id="community">
            <option value="0">请选择园区</option>
            <volist name="community" id="vo">
                <option value="{BEESCRM:$vo.community_id}">{BEESCRM:$vo.community_name}</option>
            </volist>
        </select>
        <select id="building">
            <option value="0">请选择楼幢</option>
            <volist name="building" id="vo">
                <option value="{BEESCRM:$vo.building_id}">{BEESCRM:$vo.building_name}</option>
            </volist>
        </select>
        <select id="floor">
            <option value="0">请选择楼层</option>
            <volist name="floor" id="vo">
                <option value="{BEESCRM:$vo.floor_id}">{BEESCRM:$vo.floor_name}</option>
            </volist>
        </select>
        <select id="room">
            <option value="0">请选择寝室</option>
            <volist name="room" id="vo">
                <option value="{BEESCRM:$vo.room_id}">{BEESCRM:$vo.room_name}</option>
            </volist>
        </select>
    </case>
</switch>
<a href="javascript:void(0)" class="btn doEdit">注册</a>
<script src="/assets/base/forum/js/jquery-2.1.0.min.js"></script>
<script>
    var type = {BEESCRM:$type};
    var irs_fee_id = {BEESCRM:$irs_fee_id};
    $('.doEdit').on('click',function(){
        ifdatalegal(type);
        var json = {};
        var info = {};
        switch(type){
            case 1:
                info.type = 1;
                info.real_name = $('#real_name').val();break;
            case 2:
                info.type = 2;
                info.number = $('#number').val();break;
            case 3:
                info.type = 3;
                info.mobile = $('#mobile').val();break;
            case 4:
                info.type = 4;
                info.community_name = $('#community option:selected').text();
                info.community_id = $('#community').val();
                info.building_name = $('#building option:selected').text();
                info.building_id = $('#building').val();
                info.floor_name = $('#floor option:selected').text();
                info.floor_id = $('#floor').val();
                info.room_name = $('#room option:selected').text();
                info.room_id = $('#room').val();
        }
        $.ajax({
            'url': "/base/irsFee/doEdit/irs_fee_id/"+irs_fee_id,
            'data': info,
            'dataType':'json',
            'type': 'POST',
            'async': false,
            success: function(data) {
                if (data.status == 'S') {
                    setTimeout(location.href="/base/irsFee/userCenter/irs_fee_id/"+irs_fee_id, 2000);
                    fm.alert(data.message);

                }else{
                    fm.alert(data.message);
                    return false;
                }
            }
        });
    });

    function ifdatalegal(type){
        switch(type){
            case 1:
                if(!$("#real_name").val().match(/^[\u4e00-\u9fa5]{1,10}$/)){
                    alert('请填写正确的姓名');return;
                }break;
            case 2:
                if($('#number').val().match(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/)){
                    alert('请填写正确的身份证号');return;
                }break;
            case 3:
                if(!$("#mobile").val().match(/^1[3|4|5|8][0-9]\d{4,8}$/)){
                    alert('请填写正确的手机号');return;
                }break;
            case 4:
                if($('#community').val() == 0){
                    alert('请选择园区');return;
                }
                if($('#building').val() == 0){
                    alert('请选择楼幢');return;
                }
                if($('#floor').val() == 0){
                    alert('请选择楼层');return;
                }
                if($('#room').val() == 0){
                    alert('请选择寝室');return;
                }
        }
    }

    //获取楼幢
    $('#community').on('change',function(){
        var communityId = $('#community').val();
        if(communityId == 0){
            $('#building').val(0);
            $('#floor').val(0);
            $('#room').val(0);
        }else{
            getBuildingInfo(communityId,'building');
        }
    });

    //获取楼层
    $('#building').on('change',function(){
        var buildingId = $('#building').val();
        if(buildingId == 0){
            $('#floor').val(0);
            $('#room').val(0);
        }else{
            getFloorInfo(buildingId,'floor');
        }
    });

    //获取寝室
    $('#floor').on('change',function(){
        var floorId = $('#floor').val();
        if(floorId == 0){
            $('#room').val(0);
        }else{
            getRoomInfo(floorId,'room');
        }
    });

    //插入楼幢信息
    function getBuildingInfo(id,div){
        var building = getBuilding(id);
        var options = [];
        var option = '<option value="0">请选择楼幢</option>';
        options.push(option);
        if(building){
            $.each(building, function (index, node) {
                var option = '<option value="' + node.building_id+'" data-name="'+node.building_name+'" data-num="' + node.building_code + '">' + node.building_name + '</option>';
                options.push(option);
            });
        }
        $('#'+div).html(options);
    }

    // 插入楼层信息
    function getFloorInfo(id,div){
        var floor = getFloor(id);
        var options = [];
        var option = '<option value="0">请选择楼层</option>';
        options.push(option);
        if(floor){
            $.each(floor, function (index, node) {
                var option = '<option value="' + node.floor_id+'" data-name="'+ node.floor_name +'">' + node.floor_name + '</option>';
                options.push(option);
            });
        }
        $('#'+div).html(options);
    }

    // 插入寝室信息
    function getRoomInfo(id,div){
        var room = getRoom(id);
        var options = [];
        var option = '<option value="0">请选择房间</option>';
        options.push(option);
        if(room){
            $.each(room, function (index, node) {
                var option = '<option value="' + node.room_id+'" data-name="' + node.room_name+ '">' + node.room_name + '</option>';
                options.push(option);
            });
        }
        $('#'+div).html(options);
    }

    function getBuilding(id) {
        var id = id ? id : 0;
        var result = null;
        $.ajax({
            url: "/base/common/getBuildingList",
            type: "post",
            dataType: 'json',
            async: false,
            data:{communityId:id},
            success: function (data) {
                if (data.status == 'S') {
                    result = data.data;
                }
            }
        });
        return result;
    }

    function getFloor(id) {
        var id = id ? id : 0;
        var result = null;
        $.ajax({
            url: "/base/common/getFloorList",
            type: "post",
            dataType: 'json',
            async: false,
            data:{buildingId:id},
            success: function (data) {
                if (data.status == 'S') {
                    result = data.data;
                }
            }
        });
        return result;
    }

    function getRoom(id) {
        var id = id ? id : 0;
        var result = null;
        $.ajax({
            url: "/base/common/getRoomList",
            type: "post",
            dataType: 'json',
            async: false,
            data:{floorId:id},
            success: function (data) {
                if (data.status == 'S') {
                    result = data.data;
                }
            }
        });
        return result;
    }

</script>